package mo.offer_version2;

import java.util.HashMap;
import java.util.Map;

public class L50 {

    public char firstUniqChar(String s) {
        //leetcode
        Map<Character, Integer> char2count = new HashMap<>();
        for (char c : s.toCharArray()) {
            Integer count = char2count.get(c);
            if (count == null) {
                count = 1;
            } else {
                count++;
            }
            char2count.put(c, count);
        }
        char res = ' ';
        for (char c : s.toCharArray()) {
            if (char2count.get(c) == 1) {
                res = c;
                break;
            }
        }
        return res;
    }

}
